﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.Unity.InterceptionExtension;
using Microsoft.Practices.Unity;

namespace Infrastructure.ConsoleClient.Interceptors
{
    public class ExecutionTimeInterceptor : ICallHandler
    {
        private IUnityContainer ContainerService { get; set; }
        public ExecutionTimeInterceptor(IUnityContainer container)
        {
            this.ContainerService = container;
        }


        public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
        {
            var sw = new System.Diagnostics.Stopwatch();
            sw.Start();
            var result = getNext()(input, getNext);
            sw.Stop();
            Console.WriteLine("Execution time in miliseconds {0}", sw.ElapsedMilliseconds);
            return result; 
        }

        public int Order { get; set; }
    }
}
